//test
export const getCount = state => {
    return state.count
}
import axios from 'axios'
const teacher = {
    state:{
        lists: [],
        pagiConfig:{
            currentPage:1,
            pageSize:3
        },
        totalPage:0,
        total:0
   },
   mutations: {
    getList(state,arr){
        state.lists = arr
    },
    getCurrentPage(state,num){
        state.pagiConfig.currentPage = num
    },
    setTotalPage(state,num){
        state.totalPage = Math.ceil(num/state.pagiConfig.pageSize)
    },
    setTotal(state,num){
        state.total = num
    },
    getPageSize(state,num){
        state.pagiConfig.pageSize = num
    }
   },
   actions: {
        //  获取数据信息
        getUserData({commit,state}){
          return  axios.get('http://localhost/api.php/testlist',{
              params:{
                transform:1,
                order:'id,desc',
                page:state.pagiConfig.currentPage+','+state.pagiConfig.pageSize
              }
          })
            .then(res=>{
                commit('setTotal',res.data._results)
                commit('setTotalPage',res.data._results)
                commit('getList',res.data.testlist)
            })
        },
        // 新增试题信息
        potTestData({commit},obj){
          return  axios.post('http://localhost/api.php/testlist',obj)
            .then(res =>{
                console.log(res.data)
            })
        },
        // 删除试题信息
        delTestData({commit},id){
            return axios.delete('http://localhost/api.php/testlist/'+id)
            .then( res =>{
                console.log(res.data)
            })
        },
        // 修改试题信息
        updateTestData({commit},obj){
            return axios.put('http://localhost/api.php/testlist/'+obj.id,obj)
            .then( res =>{
                console.log(res.data)
            })
        }
   }

}
export default teacher